package cn.yangliu.test;

import com.baidu.ueditor.UEditorConfig;
import com.baidu.ueditor.web.UEditorController;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.web.servlet.handler.SimpleUrlHandlerMapping;

import java.util.Properties;

/**
 * 作者 杨柳
 * 创建时间 2017-09-01 21:26
 */
@SpringBootApplication
public class Application {

    @Bean
    public UEditorConfig uEditorConfig(){
        UEditorConfig config = new UEditorConfig();
        //设置统一前缀
        config.setGlobalUrlPreffix("http://localhost/static");
        //设置ueditor的配置文件位置

        config.setGlobalSavePathPreffix("/home/static");
        config.setConfigPath("classpath:ueditor.properties");
        return config;
    }

    @Bean
    public UEditorController uEditorController(){
        return new UEditorController();
    }

    /**
     * serverUrl 和controller绑定
     * @return
     */
    @Bean
    public SimpleUrlHandlerMapping ueSimpleUrlHandlerMapping() {
        SimpleUrlHandlerMapping handlerMapping = new SimpleUrlHandlerMapping();
        Properties prop = new Properties();
        prop.setProperty("/ueditor", "uEditorController");
        handlerMapping.setMappings(prop);
        return handlerMapping;
    }

    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }
}
